//
//  GroupViewController.m
//  FH JOANNEUM
//
//  Created by Daniel Hösele on 10.11.2014.
//  Copyright (c) 2014 Daniel Hösele. All rights reserved.
//

#import "GroupViewController.h"
#import "SettingsManager.h"

@interface GroupViewController ()
@property (nonatomic) NSMutableArray *groups;
@end

@implementation GroupViewController

@synthesize groups = _groups;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];

    // Array of selectable groups
    _groups = [[NSMutableArray alloc] init];
    
    [_groups addObject:@"Show all"];
    [_groups addObject:@"Hide all"];
    
    [_groups addObject:@"G1"];
    [_groups addObject:@"G2"];
    [_groups addObject:@"G3"];
    
    [_groups addObject:@"GA"];
    [_groups addObject:@"GB"];
    [_groups addObject:@"GC"];
}

- (void)viewWillDisappear:(BOOL)animated {
    
    //[[NSNotificationCenter defaultCenter] postNotificationName:@"DoUpdate" object:nil userInfo:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [_groups count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    [cell.textLabel setText:[_groups objectAtIndex:indexPath.row]];
    
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    // set new selected year
    [[SettingsManager sharedInstance] setGroup:[_groups objectAtIndex:indexPath.row]];
    
    // pop the viewcontroller of the navigationcontroller stack
    [self.navigationController popViewControllerAnimated:YES];
}


@end
